package com.brspace.qualitycontrol.controller.admin;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.MeetApply;
import com.brspace.qualitycontrol.mapper.MeetApplyMapper;
import com.brspace.qualitycontrol.service.MeetApplyService;
import com.brspace.qualitycontrol.service.ProcessNodeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 会议申请 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Api(description = "三重一大")
@CrossOrigin
@RestController
@RequestMapping("/admin/meet-apply")
public class MeetApplyController {
    @Resource
    private MeetApplyService meetApplyService;
    @Resource
    private MeetApplyMapper meetApplyMapper;
    @Resource
    private ProcessNodeService processNodeService;

    /**
     * 新建会议申请
     *
     * @author Hugo
     * @date 2021-04-08 18:59
     **/
    @ApiOperation("新建会议申请")
    @PostMapping("addMeetApp")
    public R addMeetApp( MeetApply meetApply) {
        meetApplyService.saveInfo(meetApply);
        return R.ok();
    }

    /**
     * 获取会议信息
     *
     * @author Hugo
     * @date 2021-04-09 11:16
     **/
    @PostMapping("openInfo/{id}")
    public R openInfo(@PathVariable String id) {
        return R.ok().data("list", meetApplyMapper.selectById(id)).data("sort",processNodeService.findSortSanZhong(id));
    }

    /**
     * 获取饼状图表格数据
     *
     * @author Hugo
     * @date 2021-04-09 13:39
     **/
    @PostMapping("getChart")
    public R getChart() {
        return R.ok().data("list", meetApplyService.getTotle());
    }

    /**
     * 获取折线图表格数据
     * @author Hugo
     * @date 2021-04-09 14:56
     **/
    @PostMapping("getChartZX")
    public R getChartZX() {
        return R.ok().data("list", meetApplyService.getChart());
    }

    /**
     * 会议申请列表
     *
     * @return
     */
    @ApiOperation("会议申请列表")
    @GetMapping("list")
    public R list() {
        List<MeetApply> list = meetApplyService.list();
        return R.ok().data("total", list);
    }

    /**
     * 会议申请分页
     *
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation("会议申请分页")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码", required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit
    ) {
        Page<MeetApply> pageParam = new Page<>(page, limit);
        IPage<MeetApply> pageModel = meetApplyService.selectPage(pageParam, null);
        List<MeetApply> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total", total).data("rows", records);
    }

    @ApiOperation("代办")
    @PostMapping("list/{page}/{limit}/{uid}")
    public R pageList1(@ApiParam(value = "当前页码", required = true) @PathVariable int page,
                       @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
                       @ApiParam(value = "当前登录用户") @PathVariable String uid){
        return meetApplyService.selectPage01(page,limit,uid);
    }
    @ApiOperation("已办")
    @PostMapping("list1/{page}/{limit}/{uid}")
    public R pageList2(@ApiParam(value = "当前页码", required = true) @PathVariable int page,
                       @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
                       @ApiParam(value = "当前登录用户") @PathVariable String uid){
        return meetApplyService.selectPage02(page,limit,uid);
    }

    @ApiOperation("审核")
    @PostMapping("/examine/{userName}/{uid}")
    public R examine(  MeetApply meetApply,
                     @ApiParam(value = "下阶段办理人ID" ,required = true) @PathVariable String userName,
                     @ApiParam(value = "当前节点办理人ID" , required = true) @PathVariable String uid ){
        return meetApplyService.examine(meetApply,userName,uid);
    }

}

